fix: stream database dumps to support large databases (#59)#129
Open
xyaz1313 wants to merge 1 commit intoouterbase:mainfrom
Open
fix: stream database dumps to support large databases (#59)#129xyaz1313 wants to merge 1 commit intoouterbase:mainfrom
xyaz1313 wants to merge 1 commit intoouterbase:mainfrom
Conversation
Previously, dumpDatabaseRoute loaded ALL table data into memory before sending the response. For databases >1GB this caused: 1. Out-of-memory crashes 2. 30-second Cloudflare Workers timeout This commit rewrites the dump to use ReadableStream with LIMIT/OFFSET batching: - Fetches rows in batches of 500 (constant BATCH_SIZE) - Streams INSERT statements incrementally via ReadableStream - Yields control between batches (10ms breathing interval) to avoid starving other concurrent requests - Escapes identifiers with double-quotes and values with proper SQL quoting (strings, NULL, blobs, booleans) - Peak memory is now O(BATCH_SIZE) instead of O(database_size) All existing tests pass, plus new tests for NULL handling and multi-batch streaming.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Fixes #59
The endpoint loads ALL table data into memory before sending the response. For large databases (1GB+), this causes:
Solution
Rewrote to use **** with LIMIT/OFFSET batching:
Changes
Testing
All 25 export tests pass:
Design Decisions